package com.bert.generator.base;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class JavaPathConfig {

    /**
     * 父模块
     */
    private String module;

    /**
     * 子模块
     */
    private String childrenModule;

    /**
     * 子模块生成文件后缀
     */
    private String fileExtension;

    /**
     * 模板路径
     */
    private String templatePath;

    /**
     * 配置需要生成代码的模块
     */
    private static List<String> moduleList = new ArrayList<>();
    /**
     * 生成代码的配置表
     */
    private static List<JavaPathConfig> pathConfigList = new ArrayList<>();

    public List<String> getmoduleList(){
        return this.moduleList;
    }

    public Map<String, List<JavaPathConfig>> getPathConfigList(){
         return pathConfigList.stream().collect(Collectors.groupingBy(JavaPathConfig::getModule));
    }

    static {

        moduleList.addAll(Arrays.asList("all", "cloud", "job", "param", "rest", "rpc", "service"));

        addPathConfigList("cloud",  "api",        "Cloud.java",   "templates/Java/cloud/Cloud.ftl");
        addPathConfigList("cloud",  "transfer",   "BOToDTO.java", "templates/Java/cloud/BOToDTO.ftl");
        addPathConfigList("cloud",  "job",        "JobCloud.java","templates/Java/cloud/JobCloud.ftl");

        addPathConfigList("job",    "api",        "JobApi.java",        "templates/Java/job/JobApi.ftl");
        addPathConfigList("job",    "remote",     "JobRemote.java",     "templates/Java/job/JobRemote.ftl");

        addPathConfigList("param",  "param",      "Param.java",         "templates/Java/param/Param.ftl");

        addPathConfigList("rest",   "transfer",   "BOToVO.java",        "templates/Java/rest/BOToVO.ftl");
        addPathConfigList("rest",   "ding/api",   "Ding.java",          "templates/Java/rest/Ding.ftl");
        addPathConfigList("rest",   "ding/vo",    "DVO.java",           "templates/Java/rest/DVO.ftl");
        addPathConfigList("rest",   "mobile/api", "Mobile.java",        "templates/Java/rest/Mobile.ftl");
        addPathConfigList("rest",   "mobile/vo",  "MVO.java",           "templates/Java/rest/MVO.ftl");
        addPathConfigList("rest",   "restful/api","Restful.java",       "templates/Java/rest/Restful.ftl");
        addPathConfigList("rest",   "restful/vo", "RVO.java",           "templates/Java/rest/RVO.ftl");
        addPathConfigList("rest",   "wechat/api", "Wechat.java",        "templates/Java/rest/Wechat.ftl");
        addPathConfigList("rest",   "wechat/vo",  "WVO.java",           "templates/Java/rest/WVO.ftl");

        addPathConfigList("rpc",    "api",        "Api.java",           "templates/Java/rpc/Api.ftl");
        addPathConfigList("rpc",    "dto",        "DTO.java",           "templates/Java/rpc/DTO.ftl");
        addPathConfigList("rpc",    "remote",     "Remote.java",        "templates/Java/rpc/Remote.ftl");

        addPathConfigList("service","bo",         "BO.java",            "templates/Java/service/BO.ftl");
        addPathConfigList("service","cache",      "Cache.java",         "templates/Java/service/Cache.ftl");
        addPathConfigList("service","cache/impl", "CacheImpl.java",     "templates/Java/service/CacheImpl.ftl");
        addPathConfigList("service","entity",     "Entity.java",        "templates/Java/service/Entity.ftl");
        addPathConfigList("service","mapper",     "Mapper.java",        "templates/Java/service/Mapper.ftl");
        addPathConfigList("service","service",    "Service.java",       "templates/Java/service/Service.ftl");
        addPathConfigList("service","service/impl","ServiceImpl.java",  "templates/Java/service/ServiceImpl.ftl");

    }

    private static void addPathConfigList(String module, String childrenModule, String fileExtension, String templatePath){
        pathConfigList.add(JavaPathConfig.builder()
                .module(module)
                .childrenModule(childrenModule)
                .fileExtension(fileExtension)
                .templatePath(templatePath)
                .build());
    }


}
